package com.examples.AppoointmentManager;



import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;

public class agenda extends Activity implements View.OnClickListener {
	private EditText ed1;
	private EditText ed2;
	private EditText ed3;
	private DatePicker ed4;
	private TimePicker ed5;
	private Button button02;
	private Button button03;
	String  date,time;
	private TextView mDateDisplay;
    private Button mPickDate;
	private int mYear;
	private int mMonth;
	private int mDay;
	private TextView mTimeDisplay;
    private Button mPickTime;

    private int mHour;
    private int mMinute;

        static final int TIME_DIALOG_ID = 0;
	
	    static final int DATE_DIALOG_ID = 1;
	
	//private Button rButton1;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.agenda);
        ed1 = (EditText)findViewById(R.id.editText1);
        ed2 = (EditText)findViewById(R.id.editText2);
        ed3 = (EditText)findViewById(R.id.editText3);
        ed4=(DatePicker)findViewById(R.id.datePicker1);
        ed5=(TimePicker)findViewById(R.id.timePicker1);
        
        
        button02=(Button)findViewById(R.id.button2);             //Map button intent
        button02.setOnClickListener(new View.OnClickListener(){
        	@Override
            public void onClick(View v) {
        		Intent myIntent = new Intent(agenda.this, LocateOnMapActivity.class);
                startActivity(myIntent);}});
	
        button03=(Button)findViewById(R.id.button1);             //Reminder button intent
        //------------------------------------------------
        // capture our View elements
        mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
        mPickDate = (Button) findViewById(R.id.pickDate);
       // capture our View elements
        mTimeDisplay = (TextView) findViewById(R.id.timeDisplay);
        mPickTime = (Button) findViewById(R.id.pickTime);
        // add a click listener to the button
        mPickTime.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(TIME_DIALOG_ID);
            }
        });
        // add a click listener to the button
        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });

        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
 
        // display the current date (this method is below)
        updateDisplay();
        // get the current time
        final Calendar d = Calendar.getInstance();
        mHour = d.get(Calendar.HOUR_OF_DAY);
        mMinute = d.get(Calendar.MINUTE);

        // display the current date
        updateDisplayTime();
 
        
        //------------------------------------------------
       /* tempyear=ed4.getYear();  
        tempmonth=ed4.getMonth();
        tempday=ed4.getDayOfMonth();
        date=tempday.toString()+"/"+tempmonth.toString()+"/"+tempyear.toString();
       */ 
        /*temphour=ed5.getCurrentHour();
        tempmin=ed5.getCurrentMinute();
        time=temphour.toString()+"/"+tempmin.toString();
        */
       
        button03.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(v == button03){
		            Intent intent = new Intent(getApplicationContext(),Reminder.class);
		            intent.putExtra("ag2",ed1.getText().toString());
		            intent.putExtra("pe2", ed2.getText().toString());
		            intent.putExtra("de2", ed3.getText().toString());
		            intent.putExtra("da2", date);
		            intent.putExtra("ti2", time);
		            
		            startActivity(intent);
		        }
				
			}
		});
        
        
	}
	
	 // updates the date in the TextView
    private void updateDisplay() {
        mDateDisplay.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mMonth + 1).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" "));
        date=mDateDisplay.getText().toString();
    }
    
 // updates the time we display in the TextView
    private void updateDisplayTime() {
        mTimeDisplay.setText(
            new StringBuilder()
                    .append(pad(mHour)).append(":")
                    .append(pad(mMinute)));
        time=mTimeDisplay.getText().toString();
    }

    private static String pad(int c) {
        if (c >= 10)
            return String.valueOf(c);
        else
            return "0" + String.valueOf(c);
    }
    
 // the callback received when the user "sets" the time in the dialog
    private TimePickerDialog.OnTimeSetListener mTimeSetListener =
        new TimePickerDialog.OnTimeSetListener() {
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                mHour = hourOfDay;
                mMinute = minute;
                updateDisplayTime();
            }
        };
    
        

       
        
    // the callback received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    updateDisplay();
                }
            };
            
            @Override
            protected Dialog onCreateDialog(int id) {
                switch (id) {
                case DATE_DIALOG_ID:
                    return new DatePickerDialog(this,
                                mDateSetListener,
                                mYear, mMonth, mDay);
                case TIME_DIALOG_ID:
                    return new TimePickerDialog(this,
                            mTimeSetListener, mHour, mMinute, false);
                
                }
                
                return null;
            }                
    

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
	
}